/* Creazione di una nuova area */
/*
| ?- AC=29,api(API),trx(Trx),lmax(Lmax),deltaL(DeltaL),area(AC,[_,_,ACd]),area(A
C,[ACx,ACy,ACd]),ACd+DeltaL<Lmax, NAx is -(ACx,/(DeltaL,2)),NAy is -(ACy,/(Delta
L,2)),NAd is ACd+DeltaL,NA1=30,sitiInteresseIn(AC,SitiAC),sitiInteresseIn(NA1,Si
tiNA1),lmax(Lmax),(SitiAC=SitiNA1,NAd<Lmax),nuovaArea(NA1,NA) --25.


| ?- AC=30,api(API),trx(Trx),lmax(Lmax),deltaL(DeltaL),area(AC,[_,_,ACd]),area(A
C,[ACx,ACy,ACd]),ACd+DeltaL<Lmax, NAx is -(ACx,/(DeltaL,2)),NAy is -(ACy,/(Delta
L,2)),NAd is ACd+DeltaL,(NAd<Lmax),NA1=31,sitiInteresseIn(AC,SitiAC),sitiInteres
seIn(NA1,SitiNA1),(SitiAC=SitiNA1,NAd<Lmax), nuovaArea(NA1,NA) --25..

*/

nuovaArea(AC,NA):-
	deltaL(DeltaL),
	area(AC,[ACx,ACy,ACd]),
	NAx is -(ACx,/(DeltaL,2)),
	NAy is -(ACy,/(DeltaL,2)),
	
	NAd is ACd+DeltaL, %---
	lmax(Lmax),			%--
	((area(NA1,[NAx,NAy,NAd]),!);
		(idArea(NA1),assert(area(NA1,[NAx,NAy,NAd])),writeln('Creo area'))),
	sitiInteresseIn(AC,SitiAC),
	sitiInteresseIn(NA1,SitiNA1),
	lmax(Lmax),
	((SitiAC=SitiNA1,NAd<Lmax)->
				(nuovaArea(NA1,NA),rimuoviArea(NA1))
				;
				(NA=NA1)
	),
		
	[aggregs].
